package factory_pattern;

/**
 * @author wangzg13
 * @since 2022/9/14
 */
public class HumanFactory extends AbstractHumanFactory {


    @Override
    public <T extends Human> T createHuman(Class<T> c) {
        // 依据传入的class对象创建对应实例对象
        try {
            return (T) Class.forName(c.getName()).newInstance();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
